﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using YYTea.MOdel.Model;
using YYTea.Services.IServices;
using YYTea.Services.VModel;

namespace youyouMiljyTea.Controllers
{

    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductController : ControllerBase
    {
        protected readonly IProduct _product;

        public ProductController(IProduct product)
        {
            _product = product;
        }

        [HttpGet()]
        public async Task<IActionResult> GetAllProduct()
        {
            var allPro = await _product.GetAllProduct();
            return Ok(allPro);
        }


        [HttpGet("Id")]
        public async Task<IActionResult> GetProductById(Guid Id)
        {
            var proById = await _product.GetProductByID(Id);
            return Ok(proById);
        }

        [HttpGet("Name")]
        public async Task<IActionResult> GetProductByName(string Name)
        {
            var proByName = await _product.GetProductByName(Name);
            return Ok(proByName);
        }

        [HttpPost()]
        //[Authorize(AuthenticationSchemes = "Bearer")]
        //[Authorize(Roles = "Admin")]
        public async Task<IActionResult> AddProduct(ProductVModel ProVM)
        {
            var proAdd = await _product.AddProduct(ProVM);
            return Ok(proAdd);
        }

        [HttpPost()]
        public async Task<IActionResult> UpdateProduct(ProductVModel ProVM, Guid id)
        {
            var proUp = await _product.UpdateProduct(ProVM, id);
            if (proUp == null)
            {
                return NotFound();
            }
            return Ok(proUp);
        }


        [HttpPost("Id")]
        public async Task<IActionResult> DeleteProduct(Guid Id)
        {
            var depro = await _product.DeleteProduct(Id);
            return Ok(depro);
        }

    }
}
